import { get, post } from "@/utils/network.js";

/**
 * 获取所有钱包余额
 * @param {String} type 类型 goods购买商品 article 文章推广 top 置顶 donate 转账 oflfine 扫码支付
 */
export function getUserWallet(type) {
	return post("wanlshop/pay/getUserWallet", { type });
}

/**
 * 充值
 * @param code 微信返回的code
 * @param money 充值金额
 */
export function recharge(code, money) {
	return post("wanlshop/pay/recharge", { code, money, type: "wechat", method: "miniapp" });
}

/**
 * 获取银行卡信息和余额信息
 */
export function getBankAndBalance() {
	return post("wanlshop/pay/initialWithdraw", {});
}

/**
 * 提现
 * @param params 提现参数
 * @param params.money 提现金额
 * @param params.account_id 银行卡id
 * @param params.wallet_type 钱包类型 1=红包钱包,2=销售钱包,3=分佣钱包
 * @param params.withdraw_type  0:微信 1:银行卡
 */
export function submitWithdraw(params) {
	return post("wanlshop/pay/withdraw", params);
}

/**
 * 提现记录
 * @param {Number} page 页码
 * @param {Number} wallet_type 钱包类型 1=红包钱包,2=销售钱包,3=分佣钱包
 */
export function withdrawLog(page, wallet_type) {
	return post("wanlshop/pay/withdrawLog", { page, wallet_type });
}

export const walletDetail = (params) => {
	return post("/wanlshop/pay/moneyLog", params);
};

/**
 * 转赠
 * @param money 转赠金额
 * @param wallet_type 钱包类型 ‘sell’ 销售钱包 ‘commission’分销钱包
 * @param mobile 接收人手机号
 */
export const addDonate = (params) => {
	return post("/increased.Donate/AddDonate", params);
};

/**
 * 获取转赠前详情
 * @param money 金额
 * @param wallet_type 钱包类型 ‘sell’ 销售钱包 ‘commission’分销钱包
 */
export const obtainDonate = (params) => {
	return post("/increased.Donate/ObtainDonate", params);
};

/**
 * 转赠记录
 */
export const getDonateList = (params) => {
	return post("/increased.Donate/GetDonateList", params);
};

/**
 * 转赠详情
 * @param donate_id id
 */
export const getDonateDetail = (params) => {
	return post("/increased.Donate/GetDonateDetail", params);
};

/**
 * 钱包类型转文字
 * @param {string} field
 */
export const walletType2text = (field) => {
	let wallet = {
		commission: {
			name: "分佣钱包",
		},
		sell: {
			name: "销售钱包",
		},
		make_up: {
			name: "组合钱包",
		},
	};
	return wallet[field];
};

/**
 * 销售钱包计算汇率
 */
export function salesWithdrawal(money) {
	return post("wanlshop/pay/withdrawalPre", {money})
}
